//
//  RegularBusLineViewModel.m
//  didacar
//
//  Created by 度周末网络-王腾 on 15/12/2.
//  Copyright © 2015年 dzmmac. All rights reserved.
//

#import "RegularBusLineViewModel.h"
#import "RegularBusLineModel.h"
#import "AbleLineRequestModel.h"
#import "HudManager.h"
#import "NSUserDefaults+Addition.h"
@implementation RegularBusLineViewModel

-(id)init{
    self.busLines = [[NSMutableArray alloc ] init];
    self.waitLineList = [[NSMutableArray alloc ] init];
    self.requestLineModel = [[AbleLineRequestModel alloc ] init];
    self.requestWaitLineModel = [[AbleLineRequestModel alloc ] init];
    return [super init];
}

-(void)getBusLinesResultBlock:(DealDataResultBlock)resultBlock{
    
    self.requestLineModel.CityId = [[NSUserDefaults standardUserDefaults] getUserSelectedCityID];
    self.requestLineModel.PageIndex = @(self.pageIndex).stringValue;
    self.requestLineModel.PageSize  = @(self.pageCount).stringValue;
    
    WEAKSELF
    [[BaseHttpRequest sharedInstance] sendRequestToPost:AbleLine withData:self.requestLineModel alertMessage:@"" success:^(NSDictionary *dicData) {
      
        if (weakSelf.pageIndex == 1) {
            [weakSelf.busLines removeAllObjects];
        }
        
        NSArray *list = dicData[@"LineList"];
        for (NSInteger i = 0 ; i < list.count; i ++) {
            RegularBusLineModel *model = [[RegularBusLineModel alloc ] initWithDictionary:list[i]];
            [weakSelf.busLines addObject:model];
        }
        
         [weakSelf configIsLoadMore:list];
        
        resultBlock(1,nil,nil);
    } error:^(NSString *errorMsg) {
        
        resultBlock(0,nil,errorMsg);
    }];
}

/**
 *  获取待开通路线
 *
 *  @param resultBlock
 */
-(void)getWaitLineListResultBlock:(DealDataResultBlock)resultBlock{
    self.requestWaitLineModel.CityId = [[NSUserDefaults standardUserDefaults] getUserSelectedCityID];
    self.requestWaitLineModel.PageIndex = @(self.pageIndex).stringValue;
    self.requestWaitLineModel.PageSize  = @(self.pageCount).stringValue;
    
    WEAKSELF
    [[BaseHttpRequest sharedInstance] sendRequestToPost:WaiteLine withData:self.requestWaitLineModel alertMessage:@"" success:^(NSDictionary *dicData) {
        
        if (weakSelf.pageIndex == 1) {
            [weakSelf.waitLineList removeAllObjects];
        }
        
        NSArray *list = dicData[@"waitLineList"];
        for (NSInteger i = 0 ; i < list.count; i ++) {
            RegularBusLineModel *model = [[RegularBusLineModel alloc ] initWithDictionary:list[i]];
            [weakSelf.waitLineList addObject:model];
        }
        
        [weakSelf configIsLoadMore:list];
        
        resultBlock(1,nil,nil);
    } error:^(NSString *errorMsg) {
        
        resultBlock(0,nil,errorMsg);
    }];
}

@end
